package com.shxc.smarttrade.old.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.old.bean.PaymentInfo;
import com.shxc.smarttrade.old.utils.BaseUtils;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jcdev1 on 2017/5/10.
 */

public class MoneyRecordAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private LayoutInflater mInflater;
    private Context mContext;
    private List<PaymentInfo.DataBean.PaymentBean> paymentBeanList;

    public MoneyRecordAdapter(Context mContext) {
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setDatas(List<PaymentInfo.DataBean.PaymentBean> paymentBeanList) {
        this.paymentBeanList = paymentBeanList;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MoneyRecordViewholder(mInflater.inflate(R.layout.adapter_money_record, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
/* 1 有记录 2 有请求链接生成的记录 3 支付接入商返回失败 4 确认支付成功 5 开户赠金 7信用值 0 无此单 -1 已提交 -2 已撤销 -3 处理中 -4 拒绝出金 -5 出金处理完毕*/
        if (holder instanceof MoneyRecordViewholder) {
            PaymentInfo.DataBean.PaymentBean pb = paymentBeanList.get(position);
            if (pb.getDirection() == 1)
                ((MoneyRecordViewholder) holder).tvRechargeOrWithdraw.setText("充值 " + BaseUtils.dealSymbol(pb.getUsdAmount()));
            else
                ((MoneyRecordViewholder) holder).tvRechargeOrWithdraw.setText("提现 " + BaseUtils.dealSymbol(pb.getUsdAmount()));
            ((MoneyRecordViewholder) holder).tvChinaYuan.setText("约合人民币：" + pb.getRmbAmount());
            ((MoneyRecordViewholder) holder).tvTime.setText(pb.getTime());
            if (pb.getStatus() == 1)
                ((MoneyRecordViewholder) holder).tvStatus.setText("有记录");
            else if (pb.getStatus() == 2)
                ((MoneyRecordViewholder) holder).tvStatus.setText("有请求链接生成的记录");
            else if (pb.getStatus() == 3)
                ((MoneyRecordViewholder) holder).tvStatus.setText("支付接入商返回失败");
            else if (pb.getStatus() == 4)
                ((MoneyRecordViewholder) holder).tvStatus.setText("确认支付成功");
            else if (pb.getStatus() == 5)
                ((MoneyRecordViewholder) holder).tvStatus.setText("开户赠金");
            else if (pb.getStatus() == 7)
                ((MoneyRecordViewholder) holder).tvStatus.setText("信用值");
            else if (pb.getStatus() == 0)
                ((MoneyRecordViewholder) holder).tvStatus.setText("无此单");
            else if (pb.getStatus() == -1)
                ((MoneyRecordViewholder) holder).tvStatus.setText("已提交");
            else if (pb.getStatus() == -2)
                ((MoneyRecordViewholder) holder).tvStatus.setText("已撤销");
            else if (pb.getStatus() == -3)
                ((MoneyRecordViewholder) holder).tvStatus.setText("处理中");
            else if (pb.getStatus() == -4)
                ((MoneyRecordViewholder) holder).tvStatus.setText("拒绝出金");
            else if (pb.getStatus() == -5)
                ((MoneyRecordViewholder) holder).tvStatus.setText("出金处理完毕");

        }
    }

    @Override
    public int getItemCount() {
        return paymentBeanList == null ? 0 : paymentBeanList.size();
    }

    public class MoneyRecordViewholder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_recharge_or_withdraw)
        TextView tvRechargeOrWithdraw;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.tv_china_yuan)
        TextView tvChinaYuan;
        @BindView(R.id.tv_time)
        TextView tvTime;

        MoneyRecordViewholder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            AutoUtils.autoSize(view);
        }
    }
}
